﻿namespace ExamV5.GradeInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class QueryGradeList : Page
    {
        protected Button butExp;
        protected Button butQuery;
        protected GridView DataGridInfo;
        protected DropDownList DDLArchiveFolder;
        protected DropDownList DDLDept;
        protected DropDownList DDLQuery;
        protected DropDownList DDLSubject;
        protected DropDownList DDLUPDept;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected Label labTip;
        protected LinkButton LBDel;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        protected LinkButton LBSelect;
        protected LinkButton LBSend;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtEndDate;
        protected TextBox txtQuery;
        protected TextBox txtStartDate;
        protected UpdatePanel UPPart;

        protected void butExp_Click(object sender, EventArgs e)
        {
            try
            {
                string cmdText = "";
                string path = base.Server.MapPath("../") + @"\PublicFile\GradeDataInfo" + this.httpCookie_3.Value + ".csv";
                string str3 = "";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                StreamWriter writer = new StreamWriter(path, true, Encoding.GetEncoding("GB2312"));
                writer.WriteLine("准考证号,考生姓名,考生性别,所属部门,所属职务,手机号码,身份证号,所属岗位,考试名称,考试科目,考试原得分,考试现得分,登陆IP,考试时间,当前标识");
                cmdText = "select b.UserSFZH,b.HandCombNO,a.JoinDate,a.LastDate,a.LoginIP,a.StartTime,a.EndTime,b.Worker,b.UserGWName,b.UserName,b.UserSex,c.UPID,c.DeptName,a.UserCode,a.PaperID,a.ExamName,a.Subject,ROUND(a.GetOldCountFen,2) as GetOldCountFen,ROUND(a.GetCountFen,2) as GetCountFen,Flag=case a.Flag when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '考试异常'  when 'Z' then '作弊标记' when 'A' then '未考' end  from ExamUser a,UserInfo b,DeptInfo c where  a.UserCode=b.UserCode and b.DeptID=c.ID and (a.Flag<>'B') ";
                if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y")
                {
                    cmdText = cmdText + " and  (a.ExamType='A' or a.ExamType='C') ";
                }
                else
                {
                    cmdText = cmdText + " and  a.ExamType='A' ";
                }
                if (this.DDLDept.SelectedItem.Value != "0")
                {
                    cmdText = cmdText + " and b.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
                }
                if ((this.DDLSubject.SelectedIndex >= 0) && (this.DDLSubject.SelectedItem.Value != "0"))
                {
                    cmdText = cmdText + " and a.Subject like '%" + this.publicFun_0.CheckString(this.DDLSubject.SelectedItem.Text.Replace("│", "").Replace("├", "")) + "%'";
                }
                if (this.txtQuery.Text.Trim() != "")
                {
                    cmdText = cmdText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
                }
                if (this.txtStartDate.Text.Trim() != "")
                {
                    cmdText = cmdText + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                }
                if (this.txtEndDate.Text.Trim() != "")
                {
                    cmdText = cmdText + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
                }
                if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='ManagGradeType'", "ParmValue").Trim().Trim() == "N")
                {
                    if (this.ViewState["ManagPower"].ToString() != "Y")
                    {
                        if (!(this.ViewState["AddPower"].ToString() == "Y"))
                        {
                            cmdText = cmdText + " and a.PaperID=0 ";
                        }
                        else
                        {
                            cmdText = cmdText + " and a.PaperID in(select ID from PaperInfo where InputUserCode='" + this.httpCookie_0.Value + "')";
                        }
                    }
                    else
                    {
                        cmdText = cmdText + " and a.PaperID<>0 ";
                    }
                }
                cmdText = cmdText + "  order by a.PaperID desc," + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand(cmdText, connection);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    str3 = "";
                    str3 = ((str3 + reader["UserCode"].ToString().Trim() + "\x00b7,") + reader["UserName"].ToString().Trim() + ",") + reader["UserSex"].ToString().Trim() + ",";
                    if (!(reader["UPID"].ToString().Trim() == "0"))
                    {
                        str3 = str3 + this.publicFun_0.GetValues("select DeptName from DeptInfo where ID=" + reader["UPID"].ToString().Trim(), "DeptName") + @"\" + reader["DeptName"].ToString().Trim() + ",";
                    }
                    else
                    {
                        str3 = str3 + reader["DeptName"].ToString().Trim() + ",";
                    }
                    str3 = ((((((((str3 + reader["Worker"].ToString().Trim() + ",") + reader["HandCombNO"].ToString().Trim() + "\x00b7,") + reader["UserSFZH"].ToString().Trim() + "\x00b7,") + reader["UserGWName"].ToString().Trim() + ",") + reader["ExamName"].ToString().Trim() + ",") + reader["Subject"].ToString().Trim() + ",") + reader["GetOldCountFen"].ToString().Trim() + ",") + reader["GetCountFen"].ToString().Trim() + ",") + reader["LoginIP"].ToString().Trim() + ",";
                    str3 = (str3 + reader["JoinDate"].ToString().Trim() + " " + reader["StartTime"].ToString().Trim() + "---" + reader["LastDate"].ToString().Trim() + " " + reader["EndTime"].ToString().Trim() + ",") + reader["Flag"].ToString().Trim() + ",";
                    writer.WriteLine(str3);
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                writer.Flush();
                writer.Close();
                this.labTip.Text = " 导出成功！单击【<a href='../FrmDownLoad.aspx?FileName=GradeDataInfo" + this.httpCookie_3.Value + ".csv' target=_blank><font color=red>下载</font></a>】进行保存";
            }
            catch
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BExpErrTip", @"alert('导出数据失败！\n\n请将PublicFile目录设置为Everyone用户可修改权限！')", true);
            }
        }

        protected void butQuery_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) == 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[3].Text.Length > Convert.ToInt32(this.ViewState["SubStrLen"].ToString()))
                {
                    e.Row.Cells[3].Text = "<a title=" + e.Row.Cells[3].Text + ">" + e.Row.Cells[3].Text.Substring(0, Convert.ToInt32(this.ViewState["SubStrLen"].ToString())) + "…</a>";
                }
                Label label = (Label) e.Row.Cells[8].FindControl("labLook");
                Label label2 = (Label) e.Row.Cells[8].FindControl("labPrint");
                label.Text = "<a href='../Persion/FrmLookPaper.aspx?UserCode=" + base.Server.UrlEncode(e.Row.Cells[1].Text) + "&PaperID=" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "' title='查看考卷详细批改信息' target='_blank'>" + label.Text + "</a>";
                label2.Text = "<a href='#' onclick=javascript:PrintInfo('" + this.DataGridInfo.DataKeys[e.Row.RowIndex]["PaperID"].ToString() + "','" + base.Server.UrlEncode(e.Row.Cells[1].Text) + "');>" + label2.Text + "</a>";
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "UserCode":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "UserName":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "ExamName":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "ExamUseTime":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "GetOldCountFen":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[6].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "Flag":
                            e.Row.Cells[7].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[6].Controls.Add(new LiteralControl("↑"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "UserCode":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "UserName":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "ExamName":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "ExamUseTime":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "GetOldCountFen":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "GetCountFen":
                            e.Row.Cells[6].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "Flag":
                            e.Row.Cells[7].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[6].Controls.Add(new LiteralControl("↓"));
                }
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (this.ViewState["SortFiled"].ToString() == sortExpression)
            {
                if (this.ViewState["SortType"].ToString() == " Desc")
                {
                    this.ViewState["SortType"] = " ASC";
                }
                else
                {
                    this.ViewState["SortType"] = " Desc";
                }
            }
            else
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            this.method_0();
        }

        protected void DDLDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void DDLSubject_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void DDLUPDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DDLDept.Items.Clear();
            this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
            if (this.DDLDept.Items.Count == 0)
            {
                if (this.DDLUPDept.SelectedItem.Value == "0")
                {
                    ListItem item = new ListItem("--所有部门--", "0");
                    this.DDLDept.Items.Insert(0, item);
                }
                else
                {
                    ListItem item2 = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                    this.DDLDept.Items.Add(item2);
                }
            }
        }

        protected void LBDel_Click(object sender, EventArgs e)
        {
            if (this.DDLArchiveFolder.SelectedItem.Value != "0")
            {
                string strSql = "";
                for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
                {
                    CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                    if (box.Checked)
                    {
                        this.method_1(this.DataGridInfo.Rows[i].Cells[1].Text, this.DataGridInfo.DataKeys[i]["PaperID"].ToString());
                        strSql = "insert into GradeArchiveFile(FolderID,ExamName,SubjectName,PaperFen,PaperDiff,RubricDist,FenDist,MemoDist,ExamTime,StartTime,EndTime,LastDate,LastTime,JoinDate,GetOldCountFen,GetCountFen,Flag,";
                        strSql = ((strSql + "UserCode,UserName,RubricS,RubricD,RubricB,RubricF,RubricA,RubricC,RubricT,RubricAN,RubricO,RubricJ,SortInfo,RubricSWrite,RubricSOK,RubricSFen,RubricDWrite,RubricDOK,RubricDFen,RubricBWrite," + "RubricBOK,RubricBFen,RubricFWrite,RubricFOK,RubricFFen,RubricAWrite,RubricAOK,RubricAFen,RubricCWrite,RubricCOK,RubricCFen,RubricTWrite,RubricTOK,RubricTFen,") + "RubricANWrite,RubricANOK,RubricANFen,RubricOWrite,RubricOOK,RubricOFen,RubricJWrite,RubricJOK,RubricJFen,CheckUserS,CheckUserD,CheckUserB,CheckUserF,CheckUserA,CheckUserC,CheckUserT,CheckUserAN,CheckUserO,CheckUserJ,InputUser,CheckUserFFen,CheckUserAFen,CheckUserCFen,CheckUserTFen,CheckUserAnFen,CheckUserOFen,CheckUserJFen," + "CheckMemoF,CheckMemoA,CheckMemoC,CheckMemoT,CheckMemoAn,CheckMemoO,CheckMemoJ) ") + " select " + this.DDLArchiveFolder.SelectedItem.Value + " as FolderID,a.ExamName,a.SubjectName,a.PaperFen,a.PaperDiff,a.RubricDist,a.FenDist,a.MemoDist,a.ExamTime,c.StartTime,c.EndTime,c.LastDate,c.LastTime,c.JoinDate,ROUND(c.GetOldCountFen,2) as GetOldCountFen,ROUND(c.GetCountFen,2) as GetCountFen,c.Flag,";
                        strSql = (((strSql + "'" + this.DataGridInfo.Rows[i].Cells[1].Text + "' as UserCode, '" + this.DataGridInfo.Rows[i].Cells[2].Text + "' as UserName,d.RubricS,d.RubricD,d.RubricB,d.RubricF,d.RubricA,d.RubricC,d.RubricT,d.RubricAN,d.RubricO,d.RubricJ,d.SortInfo,b.RubricSWrite,b.RubricSOK,b.RubricSFen,b.RubricDWrite,b.RubricDOK,b.RubricDFen,b.RubricBWrite,") + "b.RubricBOK,b.RubricBFen,b.RubricFWrite,b.RubricFOK,b.RubricFFen,b.RubricAWrite,b.RubricAOK,b.RubricAFen,b.RubricCWrite,b.RubricCOK,b.RubricCFen,b.RubricTWrite,b.RubricTOK,b.RubricTFen,") + "b.RubricANWrite,b.RubricANOK,b.RubricANFen,b.RubricOWrite,b.RubricOOK,b.RubricOFen,b.RubricJWrite,b.RubricJOK,b.RubricJFen,b.CheckUserS,b.CheckUserD,b.CheckUserB,b.CheckUserF,b.CheckUserA,b.CheckUserC,b.CheckUserT,b.CheckUserAN,b.CheckUserO,b.CheckUserJ,'" + this.httpCookie_1.Value + "'as InputUser,") + "b.CheckUserFFen,b.CheckUserAFen,b.CheckUserCFen,b.CheckUserTFen,b.CheckUserAnFen,b.CheckUserOFen,b.CheckUserJFen,b.CheckMemoF,b.CheckMemoA,b.CheckMemoC,b.CheckMemoT,b.CheckMemoAn,b.CheckMemoO,b.CheckMemoJ";
                        strSql = (strSql + " from PaperInfo a,CheckPaper b,ExamUser c,PaperData d where c.UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text + "' and c.PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString()) + " and a.ID=c.PaperID and d.PaperID=c.PaperID and d.UserCode=c.UserCode and c.PaperID=b.PaperID and c.UserCode=b.UserCode";
                        if (this.publicFun_0.ExecuteSql(strSql) == 0)
                        {
                            strSql = "insert into GradeArchiveFile(FolderID,UserCode,ExamName,SubjectName,StartTime,EndTime,GetCountFen,GetOldCountFen,Flag,LastDate,JoinDate,LastTime) ";
                            strSql = strSql + " select " + this.DDLArchiveFolder.SelectedItem.Value + " as FolderID,UserCode,ExamName,Subject,StartTime,EndTime,GetCountFen,GetOldCountFen,Flag,LastDate,JoinDate,LastTime from  ExamUser where UserCode='" + this.DataGridInfo.Rows[i].Cells[1].Text + "' and PaperID=" + this.DataGridInfo.DataKeys[i]["PaperID"].ToString();
                            this.publicFun_0.ExecuteSql(strSql);
                        }
                    }
                }
                this.DataGridInfo.PageIndex = 0;
                this.method_0();
                this.LBSelect.Text = "归档所有";
                this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('将考试成绩进行归档操作！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTrueW", @"alert('成绩归档操作成功！\n\n如此份试卷所有成绩都归档成功可以删除此试卷')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTrueC", "alert('请选择成绩档案柜！')", true);
            }
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        protected void LBSelect_Click(object sender, EventArgs e)
        {
            if (this.DDLArchiveFolder.SelectedItem.Value != "0")
            {
                string cmdText = "";
                cmdText = "select d.ExamTime,(d.ExamTime-a.LastTime) as ExamUseTime,a.StartTime,a.EndTime,b.UserName,c.DeptName,a.UserCode,a.PaperID,a.ExamName,a.Subject,ROUND(a.GetOldCountFen,2) as GetOldCountFen,ROUND(a.GetCountFen,2) as GetCountFen,Flag=case a.Flag when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '考试异常'  when 'Z' then '作弊标记' end  from ExamUser a,UserInfo b,DeptInfo c,PaperInfo d where d.ID=a.PaperID and a.UserCode=b.UserCode and b.DeptID=c.ID and (a.Flag<>'A' and a.Flag<>'B') ";
                if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y"))
                {
                    cmdText = cmdText + " and  a.ExamType='A' ";
                }
                else
                {
                    cmdText = cmdText + " and  (a.ExamType='A' or a.ExamType='C') ";
                }
                if (this.DDLDept.SelectedItem.Value != "0")
                {
                    cmdText = cmdText + " and b.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
                }
                if ((this.DDLSubject.SelectedIndex >= 0) && (this.DDLSubject.SelectedItem.Value != "0"))
                {
                    cmdText = cmdText + " and a.Subject like '%" + this.publicFun_0.CheckString(this.DDLSubject.SelectedItem.Text.Replace("│", "").Replace("├", "")) + "%'";
                }
                if (this.txtQuery.Text.Trim() != "")
                {
                    cmdText = cmdText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
                }
                if (this.txtStartDate.Text.Trim() != "")
                {
                    cmdText = cmdText + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
                }
                if (this.txtEndDate.Text.Trim() != "")
                {
                    cmdText = cmdText + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
                }
                cmdText = cmdText + "  order by a.PaperID desc," + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
                string strSql = "";
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand(cmdText, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    this.method_1(reader["UserCode"].ToString(), reader["PaperID"].ToString());
                    strSql = "insert into GradeArchiveFile(FolderID,ExamName,SubjectName,PaperFen,PaperDiff,RubricDist,FenDist,MemoDist,ExamTime,StartTime,EndTime,LastDate,LastTime,JoinDate,GetOldCountFen,GetCountFen,Flag,";
                    strSql = ((strSql + "UserCode,UserName,RubricS,RubricD,RubricB,RubricF,RubricA,RubricC,RubricT,RubricAN,RubricO,RubricJ,SortInfo,RubricSWrite,RubricSOK,RubricSFen,RubricDWrite,RubricDOK,RubricDFen,RubricBWrite," + "RubricBOK,RubricBFen,RubricFWrite,RubricFOK,RubricFFen,RubricAWrite,RubricAOK,RubricAFen,RubricCWrite,RubricCOK,RubricCFen,RubricTWrite,RubricTOK,RubricTFen,") + "RubricANWrite,RubricANOK,RubricANFen,RubricOWrite,RubricOOK,RubricOFen,RubricJWrite,RubricJOK,RubricJFen,CheckUserS,CheckUserD,CheckUserB,CheckUserF,CheckUserA,CheckUserC,CheckUserT,CheckUserAN,CheckUserO,CheckUserJ,InputUser,CheckUserFFen,CheckUserAFen,CheckUserCFen,CheckUserTFen,CheckUserAnFen,CheckUserOFen,CheckUserJFen," + "CheckMemoF,CheckMemoA,CheckMemoC,CheckMemoT,CheckMemoAn,CheckMemoO,CheckMemoJ) ") + " select " + this.DDLArchiveFolder.SelectedItem.Value + " as FolderID,a.ExamName,a.SubjectName,a.PaperFen,a.PaperDiff,a.RubricDist,a.FenDist,a.MemoDist,a.ExamTime,c.StartTime,c.EndTime,c.LastDate,c.LastTime,c.JoinDate,ROUND(c.GetOldCountFen,2) as GetOldCountFen,ROUND(c.GetCountFen,2) as GetCountFen,c.Flag,";
                    strSql = (((strSql + "'" + reader["UserCode"].ToString() + "' as UserCode, '" + reader["UserName"].ToString() + "' as UserName,d.RubricS,d.RubricD,d.RubricB,d.RubricF,d.RubricA,d.RubricC,d.RubricT,d.RubricAN,d.RubricO,d.RubricJ,d.SortInfo,b.RubricSWrite,b.RubricSOK,b.RubricSFen,b.RubricDWrite,b.RubricDOK,b.RubricDFen,b.RubricBWrite,") + "b.RubricBOK,b.RubricBFen,b.RubricFWrite,b.RubricFOK,b.RubricFFen,b.RubricAWrite,b.RubricAOK,b.RubricAFen,b.RubricCWrite,b.RubricCOK,b.RubricCFen,b.RubricTWrite,b.RubricTOK,b.RubricTFen,") + "b.RubricANWrite,b.RubricANOK,b.RubricANFen,b.RubricOWrite,b.RubricOOK,b.RubricOFen,b.RubricJWrite,b.RubricJOK,b.RubricJFen,b.CheckUserS,b.CheckUserD,b.CheckUserB,b.CheckUserF,b.CheckUserA,b.CheckUserC,b.CheckUserT,b.CheckUserAN,b.CheckUserO,b.CheckUserJ,'" + this.httpCookie_1.Value + "'as InputUser,") + "b.CheckUserFFen,b.CheckUserAFen,b.CheckUserCFen,b.CheckUserTFen,b.CheckUserAnFen,b.CheckUserOFen,b.CheckUserJFen,b.CheckMemoF,b.CheckMemoA,b.CheckMemoC,b.CheckMemoT,b.CheckMemoAn,b.CheckMemoO,b.CheckMemoJ";
                    strSql = (strSql + " from PaperInfo a,CheckPaper b,ExamUser c,PaperData d where c.UserCode='" + reader["UserCode"].ToString() + "' and c.PaperID=" + reader["PaperID"].ToString()) + " and a.ID=c.PaperID and d.PaperID=c.PaperID and d.UserCode=c.UserCode and c.PaperID=b.PaperID and c.UserCode=b.UserCode";
                    if (this.publicFun_0.ExecuteSql(strSql) == 0)
                    {
                        strSql = "insert into GradeArchiveFile(FolderID,UserCode,ExamName,SubjectName,StartTime,EndTime,GetCountFen,GetOldCountFen,Flag,LastDate,JoinDate,LastTime) ";
                        strSql = strSql + " select " + this.DDLArchiveFolder.SelectedItem.Value + " as FolderID,UserCode,ExamName,Subject,StartTime,EndTime,GetCountFen,GetOldCountFen,Flag,LastDate,JoinDate,LastTime from  ExamUser where UserCode='" + reader["UserCode"].ToString() + "' and PaperID=" + reader["PaperID"].ToString();
                        this.publicFun_0.ExecuteSql(strSql);
                    }
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
                this.DataGridInfo.PageIndex = 0;
                this.method_0();
                this.LBSelect.Text = "归档所有";
                this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('将考试成绩进行归档操作！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTrueB", @"alert('成绩归档操作成功！\n\n如此份试卷所有成绩都归档成功可以删除此试卷')", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTrueA", "alert('请选择成绩档案柜！')", true);
            }
        }

        protected void LBSend_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    this.publicFun_0.SendHandSet(this.DataGridInfo.Rows[i].Cells[1].Text.Trim(), "考试系统提醒：您的(" + this.DataGridInfo.DataKeys[i]["ExamName"].ToString() + ")考试成绩为" + this.DataGridInfo.Rows[i].Cells[6].Text.Trim() + "分", this.httpCookie_1.Value, this.httpCookie_0.Value);
                }
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BSend", "alert('考试成绩发送手机短信操作成功！')", true);
        }

        private void method_0()
        {
            string selectCommandText = "";
            selectCommandText = "select '0' as ExamUseTime,a.StartTime,a.EndTime,b.UserName,c.DeptName,a.UserCode,a.PaperID,a.ExamName,a.Subject,ROUND(a.GetOldCountFen,2) as GetOldCountFen,ROUND(a.GetCountFen,2) as GetCountFen,Flag=case a.Flag when 'C' then '考试完成' when 'D' then '客观题批改完成' when 'E' then '考试批改完成' when 'G' then '考试异常'  when 'Z' then '作弊标记' end  from ExamUser a,UserInfo b,DeptInfo c where  a.UserCode=b.UserCode and b.DeptID=c.ID and (a.Flag<>'A' and a.Flag<>'B') ";
            if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsLookTestExam'", "ParmValue").Trim() == "Y"))
            {
                selectCommandText = selectCommandText + " and  a.ExamType='A' ";
            }
            else
            {
                selectCommandText = selectCommandText + " and  (a.ExamType='A' or a.ExamType='C') ";
            }
            if (this.DDLDept.SelectedItem.Value != "0")
            {
                selectCommandText = selectCommandText + " and b.DeptID in (select b.ID from DeptInfo b where " + this.publicFun_0.GetManagDeptID(this.publicFun_0.CheckString(this.DDLDept.SelectedItem.Value)) + ")";
            }
            if ((this.DDLSubject.SelectedIndex >= 0) && (this.DDLSubject.SelectedItem.Value != "0"))
            {
                selectCommandText = selectCommandText + " and a.Subject like '%" + this.publicFun_0.CheckString(this.DDLSubject.SelectedItem.Text.Replace("│", "").Replace("├", "")) + "%'";
            }
            if (this.txtQuery.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and " + this.publicFun_0.CheckString(this.DDLQuery.SelectedItem.Value) + " like '%" + this.publicFun_0.CheckString(this.txtQuery.Text) + "%'";
            }
            if (this.txtStartDate.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and Convert(dateTime,a.JoinDate)>=Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtStartDate.Text.Trim()) + " 00:00:00')";
            }
            if (this.txtEndDate.Text.Trim() != "")
            {
                selectCommandText = selectCommandText + " and Convert(dateTime,'" + this.publicFun_0.CheckString(this.txtEndDate.Text.Trim()) + " 23:59:59')>=Convert(dateTime,a.JoinDate)";
            }
            if (this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='ManagGradeType'", "ParmValue").Trim().Trim() == "N")
            {
                if (this.ViewState["ManagPower"].ToString() == "Y")
                {
                    selectCommandText = selectCommandText + " and a.PaperID<>0 ";
                }
                else if (!(this.ViewState["AddPower"].ToString() == "Y"))
                {
                    selectCommandText = selectCommandText + " and a.PaperID=0 ";
                }
                else
                {
                    selectCommandText = selectCommandText + " and a.PaperID in(select ID from PaperInfo where InputUserCode='" + this.httpCookie_0.Value + "')";
                }
            }
            selectCommandText = selectCommandText + "  order by a.PaperID desc," + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        private void method_1(string string_0, string string_1)
        {
            string str = "";
            string values = "";
            string str3 = "";
            string cmdText = "select RubricS,RubricD,RubricB,RubricF,RubricA,RubricC,RubricT,RubricAN,RubricO,RubricJ from PaperData where UserCode='" + string_0 + "' and PaperID=" + string_1;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                str = reader["RubricS"].ToString() + reader["RubricD"].ToString() + reader["RubricB"].ToString() + reader["RubricF"].ToString() + reader["RubricA"].ToString() + reader["RubricC"].ToString() + reader["RubricT"].ToString() + reader["RubricAN"].ToString() + reader["RubricO"].ToString() + reader["RubricJ"].ToString();
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            str = str.Replace("#", ",");
            if (str.Length > 0)
            {
                str = str + "0";
            }
            else
            {
                str = "0,0";
            }
            values = this.publicFun_0.GetValues("select ID from ExamRubricInfo where ID in(" + str + ")");
            if (values.Length > 0)
            {
                values = "," + values;
            }
            else
            {
                values = ",0,";
            }
            string[] strArray = str.Split(new char[] { ',' });
            for (int i = 0; i < strArray.Length; i++)
            {
                if (values.IndexOf("," + strArray[i] + ",") <= -1)
                {
                    str3 = str3 + strArray[i] + ",";
                }
            }
            if (str3.Length > 0)
            {
                str3 = str3 + "0";
            }
            else
            {
                str3 = "0,0";
            }
            string strSql = "insert into ExamRubricInfo(ID,SubjectID,RubricType,RubricTitle,Difficulty,OptionAnswer,OKAnswer,OKMemo,RubricFilename,VodFileName,RndNumber,CreatTime,CreatNumberNO) ";
            strSql = strSql + " select ID,SubjectID,RubricType,RubricTitle,Difficulty,OptionAnswer,OKAnswer,OKMemo,RubricFilename,VodFileName,RndNumber,CreatTime,CreatNumberNO from RubricInfo where ID in (" + str3 + ")";
            this.publicFun_0.ExecuteSql(strSql);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.httpCookie_2.Value != "A")
                        {
                            this.txtQuery.Attributes.Add("onkeydown", "SubmitKeyClick('butQuery');");
                            if (!(this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='HandComb'", "ParmValue") == "1"))
                            {
                                this.LBSend.Enabled = false;
                            }
                            else
                            {
                                this.LBSend.Enabled = true;
                                this.LBSend.Attributes.Add("onclick", "javascript:{if(confirm('确定发送所有选中考试成绩信息到考生手机上吗？')==false) return false;}");
                            }
                            this.ViewState["SortFiled"] = "GetCountFen";
                            this.ViewState["SortType"] = " Desc";
                            this.DDLUPDept.DataTextField = "DeptName";
                            this.DDLUPDept.DataValueField = "ID";
                            if (!(this.httpCookie_2.Value == "C"))
                            {
                                this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where ID=" + this.httpCookie_3.Value + " order by SortInfo,ID");
                            }
                            else
                            {
                                this.DDLUPDept.DataSource = this.publicFun_0.RetrunDataView("select ID,DeptName from DeptInfo where UPID=0  order by SortInfo,ID");
                            }
                            this.DDLUPDept.DataBind();
                            if (!(this.httpCookie_2.Value == "C"))
                            {
                                this.DDLDept.Items.Clear();
                                this.publicFun_0.LoadDeptInfo(this.DDLDept, this.DDLUPDept.SelectedItem.Value, this.httpCookie_0.Value, "B");
                                if (this.DDLDept.Items.Count == 0)
                                {
                                    ListItem item2 = new ListItem(this.DDLUPDept.SelectedItem.Text, this.DDLUPDept.SelectedItem.Value);
                                    this.DDLDept.Items.Add(item2);
                                }
                            }
                            else
                            {
                                this.DDLUPDept.SelectedIndex = -1;
                                this.DDLDept.SelectedIndex = -1;
                                ListItem item3 = new ListItem("--所有单位--", "0");
                                ListItem item4 = new ListItem("--所有部门--", "0");
                                this.DDLDept.Items.Insert(0, item4);
                                this.DDLUPDept.Items.Insert(0, item3);
                            }
                            this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, "N", "B", this.httpCookie_3.Value);
                            this.DDLSubject.Items.Insert(0, new ListItem("--请选择所属科目信息--", "0"));
                            this.LBSelect.Attributes.Add("onclick", @"javascript:{if(confirm('此操作将归档您查询结果的所有成绩\n\n确定归档所有查询成绩信息吗？')==false) return false;}");
                            this.LBDel.Attributes.Add("onclick", "javascript:{if(confirm('确定归档所有选中的考试成绩信息吗？')==false) return false;}");
                            this.publicFun_0.GetFolderInfo(this.DDLArchiveFolder, "select ID,FolderName from GradeFolder where UPID=0 and  EditUserCode like '%," + this.httpCookie_0.Value + ",%'", "1", this.httpCookie_0.Value, this.httpCookie_3.Value);
                            ListItem item = new ListItem("--选择档案柜--", "0");
                            this.DDLArchiveFolder.Items.Insert(0, item);
                            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                            connection.Open();
                            SqlCommand command = new SqlCommand("select AddPaper,ManagPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                            if (reader.Read())
                            {
                                this.ViewState["AddPower"] = reader["AddPaper"].ToString();
                                this.ViewState["ManagPower"] = reader["ManagPaper"].ToString();
                            }
                            reader.Close();
                            command.Dispose();
                            connection.Close();
                            connection.Dispose();
                            string str = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='SubStrLength'", "ParmValue").Trim();
                            if (str.Trim() == "")
                            {
                                str = "20";
                            }
                            this.ViewState["SubStrLen"] = str;
                            this.method_0();
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('成绩查询权限未开放！')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

